//! \file DataBase.c
//! \brief TODO: Document
// -----------------------------------------------------------------------------
//! This program is free software; you can redistribute it and/or
//! modify it under the terms of the GNU General Public License
//! as published by the Free Software Foundation; either version 2
//! of the License, or (at your option) any later version.
//!
//! This program is distributed in the hope that it will be useful,
//! but WITHOUT ANY WARRANTY; without even the implied warranty of
//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//! GNU General Public License for more details.
//!
//! You should have received a copy of the GNU General Public License
//! along with this program; if not, write to the Free Software Foundation,
//! Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// -----------------------------------------------------------------------------

#include "DataBase.h"
#include "sqlite3.h"
#include "Core.h"

// =====[ Local Definitions ]===================================================

// =====[ Local DataTypes ]=====================================================

// =====[ Local Variables ]=====================================================
static sqlite3* pDb;


// =====[ Local Functions ]=====================================================

// =====[ Private (Internal) Methods ]==========================================
extern tERROR _DbBoolean_Initialize(sqlite3* pDataBase);

// =====[ Local Implementation ]================================================


// =============================================================================
// Implement: DB_Start
// -----------------------------------------------------------------------------
tERROR DB_Start(void)
{
  int Result;

  // Initialize the SQL server.
  if (sqlite3_initialize() != 0)
    return (DB_Stop(dERROR_DB_FAILED_TO_START));

  // Open the SQL database for use.
  if (sqlite3_open("Test.db", &pDb) != 0)
    return (DB_Stop(dERROR_DB_FAILED_TO_START));


  // TODO: turn into iteration table.
  _DbEnum_Initialize(pDb);

  // Finally, return success.
  return (dNO_ERROR);
}


// =============================================================================
// Implement: DB_Stop
// -----------------------------------------------------------------------------
tERROR DB_Stop(tERROR Error)
{
  // Close the data base.
  sqlite3_close(pDb);

  // Shutdown the SQL server.
  sqlite3_shutdown();

  // Log the stop error code.
  Core_LogError(Error);

  // Finally, return error code.
  return (Error);
}
